package com.yuan.service.impl;

import com.yuan.vo.LoginUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (!"yuan".equals(username)) {
            throw new RuntimeException("用户名错误！！！");
        }
        List<String> list = new ArrayList<>(Arrays.asList("test", "admin"));
        return new LoginUser(username,new BCryptPasswordEncoder().encode("123456"),list);
    }
}
